/*
Author: Surpass-HC
Source: https://gitee.com/hxchuan000/clpc-1
Mail: surpass-hc@qq.com
*/
#ifndef __STATE_MACHINE_MGR_H__
#define __STATE_MACHINE_MGR_H__
#include <typecomm.h>

struct statMcBaseStruct;
struct statMcMngStruct;
typedef int (*stateMachineInit)(struct statMcBaseStruct *thisState);
typedef int (*stateMachineRun)(struct statMcBaseStruct *thisState);
typedef int (*stateMachineQuit)(struct statMcBaseStruct *thisState);
struct statMcBaseStruct
{
    stateMachineInit stateInit;
    stateMachineRun stateRun;
    stateMachineQuit stateQuit;
    int stateId;
    struct statMcMngStruct *cstaMgr;
};
#define statMcInvalidID (-1)

#define statMcBaseDefine(setinit, setrun, setquit, setid, setManager) {setinit, setrun, setquit, setid, setManager}
#define statMcDefRunFun(setrun, setid, setManager) {NULL, setrun, NULL, setid, setManager}

struct statMcMngStruct
{
    struct statMcBaseStruct *statelist;
    void *staCtxt;
    int stateSize;
    int stateIdNow;
    int stateIdNext;
    int subState;
};
// state machine manage init
int statMcMngInit(struct statMcMngStruct *smnger, void *setContext, struct statMcBaseStruct *setStateBuffer,
                  int setStateSize, int initState);
// state machine manage run
int statMcMngRun(struct statMcMngStruct *smnger);
// state machine manage quit
int statMcMngQuit(struct statMcMngStruct *smnger);
// state machine manage transition
int statMcMngTranst(struct statMcMngStruct *smnger, int nextStateId);
#endif
